<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1 class="name">随机抽取</h1>
    <button>开始</button>
    <button>结束</button>


    <script src="../../JS基础/utils.js"></script>
    <script>
        //练习：随机点名
        let nameStr = `查丁予、刘安妮、向凌翔`;
        let nameArr = nameStr.split('、');

        //获取元素

        let start = document.getElementsByTagName('button')[0];
        let end = document.getElementsByTagName('button')[1];
        let h1 = document.getElementsByClassName('name')[0];
        let timer,index;
        start.onclick = function () {
            if (timer) {
                return;
            }
            timer = setInterval(() => {
                index = createRandom(0, nameArr.length - 1);
                h1.innerHTML = nameArr[index];
            }, 100)
        }

        end.onclick = function () {
            // nameArr.splice(nameArr.indexOf(h1.innerHTML),1)
            nameArr.splice(index,1)
            clearInterval(timer);
            timer = null;//每次停止后把timer的值清除掉，下一次才能重新开始
        }




    //分组抽
    //抽第几组

    </script>

</body>

</html>